﻿Public Class masgrpdrg
    Private GDCODE = Nothing
    Private GRPDRG = Nothing
    Private STATUS = Nothing
    Private selectMasgrpdrg = "SELECT `gdcode` as 'รหัสกลุ่มยา',`grpdrg` as 'ชื่อกลุ่มยา',`status` as 'สถานะการเปิดใช้งาน' FROM masgrpdrg"
    'Private selectMasgrpdrg = "SELECT GDCODE, GRPDRG, convert(bit, [STATUS]) FROM MASGRPDRG"

    Dim connect As CONDB = CONDB.NewConnection()
    'Dim connectlocal As conlocal = conlocal.NewConnection

    Property GDCODE_ As Integer
        Get
            Return GDCODE
        End Get
        Set(value As Integer)
            GDCODE = value
        End Set
    End Property

    Property GRPDRG_ As String
        Get
            Return GRPDRG
        End Get
        Set(value As String)
            GRPDRG = value
        End Set
    End Property

    Property STATUS_ As Boolean
        Get
            Return STATUS
        End Get
        Set(value As Boolean)
            If value = True Then
                STATUS = 1
            Else
                STATUS = 0
            End If
        End Set
    End Property

    Property selectMasgrpdrg_ As String
        Get
            Return selectMasgrpdrg
        End Get
        Set(value As String)

        End Set
    End Property

    Public Sub insertMasgrpdrgData()
        If TypeOf GRPDRG Is String Then
            If connect.GetTable("SELECT gdcode FROM masgrpdrg WHERE grpdrg = '" & GRPDRG & "'").Rows.Count > 0 Then
                MsgBox("มีข้อมูลกลุ่มยานี้อยู่ในระบบแล้ว")
            Else
                Try
                    connect = CONDB.NewConnection()
                    'connectlocal = conlocal.NewConnection()
                    'Dim dischargeID As Integer

                    connect.ExecuteNonQuery("INSERT INTO masgrpdrg (grpdrg, status) VALUES ('" & GRPDRG & "', '" & STATUS & "')")
                    'dischargeID = connect.ExecuteScalar("INSERT INTO masdischarge (DISCHARGE, STATUS) VALUES ('" & masdischargeDescription & "', '" & masdischargeStatus & "'); SELECT LAST_INSERT_ID();")
                    'connectlocal.ExecuteNonQuery("INSERT INTO MASDISCHARGE (DISCHGID, DISCHARGE, STATUS) VALUES ('" & dischargeID & "', '" & masdischargeDescription & "', '" & masdischargeStatus & "')")
                    MsgBox("ท่านได้ทำการเพิ่มข้อมูลกลุ่มยาเรียบร้อยแล้ว")
                Catch ex As Exception
                    MsgBox(vbCrLf & ex.Message)
                End Try
                connect.Dispose()
                'connectlocal.Dispose()
            End If
        Else
            MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร")
        End If
    End Sub

    Public Sub editMasgrpdrgData()

        If TypeOf GRPDRG Is String Then
            Try
                connect = CONDB.NewConnection()
                'connectlocal = conlocal.NewConnection()

                connect.ExecuteNonQuery("UPDATE masgrpdrg SET grpdrg = '" & GRPDRG & "', status = '" & STATUS & "' WHERE gdcode = '" & GDCODE & "'")
                'connectlocal.ExecuteNonQuery("UPDATE MASDISCHARGE SET DISCHARGE = '" & masdischargeDescription & "', STATUS = '" & masdischargeStatus & "' WHERE DISCHGID = '" & masdischargeID & "'")
                MsgBox("ท่านได้ทำการแก้ไขข้อมูลกลุ่มยาเรียบร้อยแล้ว")
            Catch ex As Exception
                MsgBox(vbCrLf & ex.Message)
            End Try
            connect.Dispose()
            'connectlocal.Dispose()
        Else
            MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร")
        End If
    End Sub
End Class
